/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.diagram.deployment.figure;

import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Rectangle;

/**
 * Defines the view of an deployment specification.
 * 
 * @author Gilles Cannenterre
 * @since 17 janv. 07
 */
public class DeploymentSpecificationFigure extends BasicArtifactFigure {

	/**
	 * 
	 * 
	 * @param keyword 
	 */
	public DeploymentSpecificationFigure(String keyword) {
		super(keyword);
		setOpaque(true);
		createContentPane();
	}

	/**
	 * 
	 */
	protected FeatureContainerFigure featureContent;
	
	/**
	 * 
	 */
	protected Figure containerFigure;
	
	/**
	 * 
	 * 
	 * @param propertyContent 
	 */
	public void addFeatureContainer(FeatureContainerFigure propertyContent) {
		this.featureContent = propertyContent;		
	}

	/**
	 * 
	 */
	protected void createContentPane()	{
		containerFigure = new Figure();
		ToolbarLayout layout = new ToolbarLayout(ToolbarLayout.VERTICAL);
		containerFigure.setLayoutManager(layout);
		add(containerFigure);	
	}

	/**
	 * Get the inner figure accepting childs figure.
	 * 
	 * @return 
	 */
	public IFigure getContentPane() {
		return containerFigure;	
	}

	/**
	 * 
	 * 
	 * @param rect 
	 */
	@Override
	public void setBounds(Rectangle rect) {
		super.setBounds(rect);
		Dimension labelFigureDimension = getLabelFigure().getPreferredSize();
		Dimension keywordFigureDimension = getKeywordFigure().getPreferredSize();
		Dimension borderFigureDimension = getBorderFigure().getPreferredSize();
		if (featureContent != null) {
			featureContent.setPreferredSize(rect.width, rect.height 
					- labelFigureDimension.height 
					- keywordFigureDimension.height 
					- borderFigureDimension.height);
		}
	}
}
